package gitapp.oschina.net.my_osc.common;

/**
 * @author Tristan-Hou
 */
public class StringUtils {

    public static int toInt(String str, int defValue){
        try{
            return Integer.parseInt(str);
        }catch (Exception e){
            return defValue;
        }
    }

    public static int toInt(Object obj){
        if (obj == null){
            return 0;
        }
        return toInt(String.valueOf(obj),0);
    }

    public static boolean toBool(String str){
        try{
            return Boolean.parseBoolean(str);
        }catch (Exception e){
            return false;
        }
    }

    public static boolean isEmtry(String str){
        if (str == null || "".equals(str)){
            return true;
        }
        for (int i = 0; i < str.length(); i++){
            char c = str.charAt(i);
            if (c != ' ' && c != '\t' && c != '\n' && c != '\r'){
                return false;
            }
        }
        return true;
    }

}
